package com.yowasa.xiuxian.engine.battle.strategy.drop.fire;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.BaseDefendStrategy;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.engine.battle.strategy.BattleStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.bo.user.UserBattle;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.entity.enums.StageEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name = "炙热余烬", upAbility = 4, needTravel = 1000)
@Order(2)
@Component
public class ChiReYuJin extends BaseDefendStrategy {

    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return ElementEnum.FIRE;
    }

    @Override
    public void limit(UserBO user) {
        if (user.getElement().get("火") < XiuxianConstants.DEFAULT_ELEMENT_ACTIVITY) {
            throw new HandlerException("学习/使用炙热余烬必须具有火灵根");
        }

    }
    @Override
    public String limitDesc() {
        return "具有火灵根";
    }

    @Override
    public String desc() {
        return "受到伤害时,物攻提高10％，速度提高5％,持续八回合,最高叠加五次\n叠满后消耗0.5攻击力的MP在行动前对对手造成以自己法攻计算的魔法伤害（不触发对方防御特性）";
    }

    @Override
    public int defend(UserBattleContent user, UserBattleContent battleUser, BattleStrategy bs, int dmg, BattleContent content) {

        BuffContent buffContent = user.getBuff().get("炽热余烬");
        if (buffContent == null) {
            BuffContent buff = new BuffContent();
            buff.setDuration(8);
            buff.setNum(1);
            user.getBuff().put("炽热余烬", buff);
        }else if(buffContent.getNum() < 5){
            buffContent.setDuration(8);
            int num=buffContent.getNum() + 1;
            buffContent.setNum(num);
        }

//        content.getMsgLog().add("炽热余烬增加一层，当前层数为："+user.getBuff().get("炽热余烬").getNum());
        UserBattle tempBattleInfo = user.getTempBattleInfo();
//
//        tempBattleInfo.setAtk((1 + tempBattleInfo.getAtk() + user.getUserBO().getUserBattle().getAtk() / 10));
//        tempBattleInfo.setSpd((1 + tempBattleInfo.getSpd() + user.getUserBO().getUserBattle().getSpd() / 20));
//        user.getBattleInfo().setAtk(tempBattleInfo.getAtk());
//        user.getBattleInfo().setSpd(tempBattleInfo.getSpd());
        if (buffContent != null && buffContent.getNum() >= 5) {
            int costMp = tempBattleInfo.getAtk() / 2;
            if (user.getBattleInfo().getCmp() >= costMp) {
                user.getBattleInfo().setCmp(user.getBattleInfo().getCmp() - costMp);
                int atk = user.getBattleInfo().getSpell();
                int tDmg = battleHelper.calAtk(atk, tempBattleInfo.getRes());
                battleUser.getBattleInfo().setChp(battleUser.getBattleInfo().getChp() - tDmg);
                content.getMsgLog().add(battleUser.getUserBO().getName() + "因对手炙热余烬效果损失" + tDmg + "点血量");
            }
        }
        return dmg;
    }


    @Override
    public boolean check(UserBattleContent user, BattleStrategy bs, BattleContent content) {
        return true;
    }


}
